package com.lxl.chat.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2配置类 访问地址 swagger-ui.html
 *
 * @date & @author: 2019/1/18 8:55 & lxl
 */
@Configuration
@EnableSwagger2
@Profile("dev")
public class Swagger2 {

    private static final String PAGE_NAME = "com.lxl.chat";
    private static final String SWAGGER_TITLE = "闪聊app系统所有API";
    private static final String SWAGGER_DESCRIBE = "可在本面板中查看/测试系统中所有API";

    /**
     * swagger2配置bean
     *
     * @return Docker
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(PAGE_NAME))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 配置信息
     *
     * @return ApiInfo
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(SWAGGER_TITLE)
                .description(SWAGGER_DESCRIBE)
                .build();
    }
}
